package icu.zqyhdm.blog.controller;

import icu.zqyhdm.blog.vo.UserInfoVo;
import icu.zqyhdm.helper.JwtHelper;
import icu.zqyhdm.result.Result;
import icu.zqyhdm.blog.entity.User;
import icu.zqyhdm.blog.service.FriendService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @Description
 * @Author lifu
 * @Date 2021/6/22 21:20
 */
@Api(tags = "用户好友接口")
@RestController
@RequestMapping(value = "/api/blog/frinend")
public class FriendController {
    @Autowired
    private FriendService friendService;

    @ApiOperation(value = "查询当前用户所有好友")
    @GetMapping(value = "/list")
    public Result list(@RequestHeader("X-Token") String token){
        List<UserInfoVo> friendList = friendService.selectList(JwtHelper.getUserId(token));
        return Result.ok(friendList);
    }

    @ApiOperation(value = "添加好友")
    @PostMapping(value = "/add/{friendId}")
    public Result add(@RequestHeader("X-Token") String token, @PathVariable Integer friendId){
        friendService.saveFriend(JwtHelper.getUserId(token), friendId);
        return Result.ok();
    }
}
